import WidgetProps from "./basic/WidgetProps";
import FLEX from './layouts/flex'
import GRID from './layouts/grid'
import CARD from './layouts/card'
import COLLAPSE from './layouts/collapse'
import INPUT from './inputs/input'
import NUMBER from './inputs/number'
import RADIO from './inputs/radio'
import CHECKBOX from './inputs/checkbox'
import SELECT from './inputs/select'
import TIMEPICKER from './inputs/timepicker'
import SWITCH from './inputs/switch'
import RATE from './inputs/rate'
import SLIDER from './inputs/slider'
import BUTTON from './other/button'
import DIVIDER from './other/divider'

const DynamicWidget:any = {
  FLEX, GRID, CARD, COLLAPSE, INPUT, NUMBER, RADIO, CHECKBOX, SELECT, TIMEPICKER, SWITCH, RATE, SLIDER, BUTTON, DIVIDER
}
export { DynamicWidget }

export type WidgetType = 'FLEX'|'GRID'|'CARD'|'COLLAPSE'|'INPUT'|'TEXTAREA'|'NUMBER'|'RADIO'|'CHECKBOX'|'SELECT'
  |'TIMEPICKER'|'TIMERANGE'|'DATEPICKER'|'DATERANGE'|'SWITCH'|'RATE'|'SLIDER'|'IMAGE'
  |'UPLOAD'|'BUTTON'|'DIVIDER'

/**
 * 组件状态 0隐藏、1占位、2只读、3编辑、4必填。
 * 234只对输入型组件有效
 */
export type WidgetStatus = '0'|'1'|'2'|'3'|'4'

export function createProps(parentProps:WidgetProps,widgetType:WidgetType,widgetProps?:WidgetProps):WidgetProps{
  if(widgetProps){
    return DynamicWidget[widgetType]?.PROPS?DynamicWidget[widgetType].PROPS(widgetProps):new WidgetProps();
  }
  const parentPropsAny = parentProps as any;
  const defaultProps = {} as any;
  if(parentPropsAny.defaultSpan){
    defaultProps.layout_reactive = {span: parentPropsAny.defaultSpan};
  }
  if(parentPropsAny.labelAlign){
    defaultProps.formitem_labelAlign = parentPropsAny.labelAlign;
  }
  if(parentPropsAny.labelWidth){
    defaultProps.formitem_labelWidth = parentPropsAny.labelWidth;
  }
  // TODO

  return DynamicWidget[widgetType]?.PROPS?DynamicWidget[widgetType].PROPS(defaultProps):new WidgetProps();
}